/**
 * File: WriteableByteChannelFactory.java
 * Created by: mhaimel
 * Created on: 28 Oct 2009
 * CVS:  $Id: WriteableByteChannelFactory.java,v 1.1 2009/12/07 10:13:48 mhaimel Exp $
 */
package uk.ac.ebi.curtain.util.file.impl;

import java.io.FileOutputStream;

import uk.ac.ebi.curtain.util.file.impl.FileAccessPool.ChannelType;

/**
 * @author mhaimel
 *
 */
public class WriteableByteChannelFactory extends AbstractFactory {
	private final ChannelType WRITER = ChannelType.WritableByteChannel;

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void _doActivateObject(FilePoolInfo info, ChannelWrapper cin)
			throws Exception {/* do nothing */}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void _doPassivateObject(FilePoolInfo info, ChannelWrapper cin)
			throws Exception {/* do nothing */}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void _openChannel(FilePoolInfo info, ChannelWrapper wrapper)
			throws Exception {
		wrapper.setChannel(
				new FileOutputStream(info.getFile(),true).getChannel()
				);		
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ChannelType getType() {
		return WRITER;
	}
}
